/*
 * Copyright (C) 2007 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package info.niwota.fwrite;

import info.niwota.fwrite.ColorPickView.OnColorChangedListener;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;

public class ColorPickDialog extends Dialog implements OnClickListener {

	private static final int COLOR_BLACK = Color.BLACK;

	private static final int COLOR_WHITE = Color.WHITE;

	private int mInitialColor;

	private OnColorChangedListener mListener;

	private ColorPickView mColorPicker;

	private View mActionWhite;

	private View mActionBlack;

	public ColorPickDialog(Context context, OnColorChangedListener listener,
			int initialColor) {
		super(context);
		mListener = listener;
		mInitialColor = initialColor;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.colordia);
		//
		OnColorChangedListener l = new OnColorChangedListener() {
			public void colorChanged(int color) {
				mListener.colorChanged(color);
				dismiss();
			}
		};
		
		mColorPicker = (ColorPickView) findViewById(R.id.picker);
		mColorPicker.setListener(l);
		mColorPicker.setSelectedColor(mInitialColor);
		//
		mActionWhite = findViewById(R.id.action_white);
		mActionBlack = findViewById(R.id.action_black);
		mActionWhite.setOnClickListener(this);
		mActionBlack.setOnClickListener(this);
	}

	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.action_black:
			mColorPicker.setSelectedColor(COLOR_BLACK);
			mColorPicker.invalidate();
			break;
		case R.id.action_white:
			mColorPicker.setSelectedColor(COLOR_WHITE);
			mColorPicker.invalidate();
			break;
		}
	}
}
